<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   Editor: R绘制中国航线分布夜景图  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
   MathJax.Hub.Config({
          tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]},
          TeX: {equationNumbers: {autoNumber: "AMS"}}
        });
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://cos.name/2014/09/visualizing-flights-data/",
                  host: "http://cos.name",
                  prePath: "http://cos.name",
                  scheme: "http",
                  pathBase: "http://cos.name/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466437241: Accept with keywords: (title(0.222222222222):航线,门户网站,统计学,分布,服务平台,中国,夜景,绘制,图, topn(0.333333333333):软件应用,统计学,R语言,内存,机场,数据挖掘,图形,放大系数,可视化,计算,文章,中国,夜景,数据,航线,函数,都市,光晕,编辑部,格式,会议,航班,绘制,代码,地图,算法,方法,评论,图像,论坛).-->
 </head>
 <body class="single single-post postid-10259 single-format-standard sidebar" onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    Editor: R绘制中国航线分布夜景图
   </h1>
  </div>
  <div class="container" id="xmain">
   <div class="hfeed site" id="page">
    <header class="site-header" id="masthead" role="banner">
     <div id="cos-logo">
      <a href="http://cos.name/">
       <img src="http://cos.name/wp-content/themes/COS-kermesinus/images/headers/cos-logo.png"/>
      </a>
     </div>
     <div class="navbar" id="navbar">
      <nav class="navigation main-navigation" id="site-navigation" role="navigation">
       <h3 class="menu-toggle">
        菜单
       </h3>
       <a class="screen-reader-text skip-link" href="http://cos.name/2014/09/visualizing-flights-data/#content" title="跳至内容">
        跳至内容
       </a>
       <div class="menu-%e6%88%91%e7%9a%84%e8%8f%9c%e5%8d%95-container">
        <ul class="nav-menu" id="menu-%e6%88%91%e7%9a%84%e8%8f%9c%e5%8d%95">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-4746" id="menu-item-4746">
          <a href="http://cos.name">
           主页
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-8120" id="menu-item-8120">
          <a href="http://cos.name/cn">
           论坛
          </a>
          <ul class="sub-menu">
           <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8124" id="menu-item-8124">
            <a href="http://cos.name/cn/wp-login.php?action=register">
             论坛注册
            </a>
           </li>
           <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8125" id="menu-item-8125">
            <a href="http://cos.name/cn/wp-login.php">
             论坛登录
            </a>
           </li>
          </ul>
         </li>
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8110" id="menu-item-8110">
          <a href="http://cos.name/books/">
           图书资料
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8112" id="menu-item-8112">
          <a href="http://cos.name/videos">
           视频教程
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8333" id="menu-item-8333">
          <a href="http://cos.name/salon/">
           统计沙龙
          </a>
         </li>
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8111" id="menu-item-8111">
          <a href="http://cos.name/chinar/">
           R语言会议
          </a>
         </li>
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8109" id="menu-item-8109">
          <a href="http://cos.name/training/">
           讲座与培训
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8115" id="menu-item-8115">
          <a href="http://cos.name/cn/forum/comprehensive/job/">
           招聘信息
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-4780" id="menu-item-4780">
          <a href="http://cos.name/about">
           关于我们
          </a>
          <ul class="sub-menu">
           <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8113" id="menu-item-8113">
            <a href="http://cos.name/2008/11/how-to-work-with-cos/">
             加入我们
            </a>
           </li>
           <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8119" id="menu-item-8119">
            <a href="http://cos.name/donate/">
             赞助我们
            </a>
           </li>
           <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8114" id="menu-item-8114">
            <a href="http://cos.name/cn/forum/26">
             项目合作
            </a>
           </li>
          </ul>
         </li>
        </ul>
       </div>
       <form action="http://cos.name/" class="search-form" method="get" role="search">
        <label>
         <span class="screen-reader-text">
          搜索：
         </span>
        </label>
       </form>
      </nav>
      <!-- #site-navigation -->
     </div>
     <!-- #navbar -->
    </header>
    <!-- #masthead -->
    <div class="site-main" id="main">
     <div class="content-area" id="primary">
      <div class="site-content" id="content" role="main">
       <article class="post-10259 post type-post status-publish format-standard hentry category-graphics category-packages category-software tag-911 tag-621 tag-859 tag-860 tag-858" id="post-10259">
        <header class="entry-header">
         <h1 class="entry-title">
          R绘制中国航线分布夜景图
         </h1>
         <div class="entry-meta">
          <span class="date">
           <a href="http://cos.name/2014/09/visualizing-flights-data/" rel="bookmark" title="链向R绘制中国航线分布夜景图的固定链接">
            <time class="entry-date" datetime="2014-09-23T11:05:19+00:00">
             2014/09/23
            </time>
           </a>
          </span>
          <span class="categories-links">
           <a href="http://cos.name/category/software/graphics/" rel="category tag">
            统计图形
           </a>
           、
           <a href="http://cos.name/category/software/packages/" rel="category tag">
            统计软件
           </a>
           、
           <a href="http://cos.name/category/software/" rel="category tag">
            软件应用
           </a>
          </span>
          <span class="tags-links">
           <a href="http://cos.name/tag/%e5%8f%af%e8%a7%86%e5%8c%96/" rel="tag">
            可视化
           </a>
           、
           <a href="http://cos.name/tag/%e5%9c%b0%e5%9b%be/" rel="tag">
            地图
           </a>
           、
           <a href="http://cos.name/tag/%e5%a4%9c%e6%99%af%e5%9b%be/" rel="tag">
            夜景图
           </a>
           、
           <a href="http://cos.name/tag/%e7%a9%ba%e9%97%b4%e6%95%b0%e6%8d%ae/" rel="tag">
            空间数据
           </a>
           、
           <a href="http://cos.name/tag/%e8%88%aa%e7%ba%bf/" rel="tag">
            航线
           </a>
          </span>
          <span class="author vcard">
           <a class="url fn n" href="http://cos.name/author/editor/" rel="author" title="查看所有由COS编辑部发布的文章">
            COS编辑部
           </a>
          </span>
         </div>
         <!-- .entry-meta -->
        </header>
        <!-- .entry-header -->
        <div class="entry-content">
         <blockquote>
          <p>
           本文作者：李根，资深数据分析师，数学爱好者。
          </p>
         </blockquote>
         <p>
          绘制数据地图是一种有效展现空间数据的方法，美丽的数据展示更容易引起读者的共鸣。本地图设计的初衷是展示中国航线的分布规律，进而可以分析成本、客流量等问题。
         </p>
         <p>
          <a href="http://cos.name/wp-content/uploads/2014/09/flight-night-scene.png">
           <img src="http://cos.name/wp-content/uploads/2014/09/flight-night-scene-500x186.png"/>
          </a>
          本文参考了以下文献进行绘制：
          <br/>
          <a href="http://spatialanalysis.co.uk/2012/06/mapping-worlds-biggest-airlines/">
           http://spatialanalysis.co.uk/2012/06/mapping-worlds-biggest-airlines/
          </a>
         </p>
         <h2>
          一、地图数据来源
         </h2>
         <p>
          地图所使用的数据均可以从网上下免费下载。
          <br/>
          航线、机场坐标：
          <a href="http://openflights.org/data.html">
           http://openflights.org/data.html
          </a>
         </p>
         <ul>
          <li>
           机场：airports.dat
          </li>
          <li>
           航线：routes.dat
          </li>
         </ul>
         <p>
          板块地图、都市地图：
          <a href="http://www.naturalearthdata.com/downloads/">
           http://www.naturalearthdata.com/downloads/
          </a>
         </p>
         <ul>
          <li>
           世界地图：ne_10m_admin_0_countries.shp
          </li>
          <li>
           都市地图：ne_10m_urban_areas.shp
          </li>
         </ul>
         <p>
          （注：都市地图是用来绘制灯光效果的。）
         </p>
         <p>
          <span id="more-10259">
          </span>
         </p>
         <h2>
          二、地图绘制所需的包
         </h2>
         <p>
          以下软件包均是绘制地图相关的，其中有一些可能没有被直接使用。
         </p>
         <pre>library(maptools)
library(ggplot2)
library(ggmap)
library(maps)
library(rgeos)
library(shapefiles)
library(geosphere)
library(plyr)
library(sp)</pre>
         <p>
          在Linux下，R语言中与地理相关的包可能需要安装如下工具：
         </p>
         <ul>
          <li>
           geos-devel-3.2.2
          </li>
          <li>
           geos-3.2.2
          </li>
         </ul>
         <p>
          这两个软件互相依赖，需要同时安装、更新。例如对于Linux CentOS 5.5，可以运行如下命令:
         </p>
         <pre>yum install geos-devel-3.2.2*.rpm geos-3.2.2*.rpm</pre>
         <h2>
          三、数据处理
         </h2>
         <p>
          这一部分的主要工作是将shapefile文件转化为R可以识别的格式，然后建立数据与地图坐标间的关联。本文使用了航线频数来计算地图航线绘制的亮度。读者根据需要可以自行关联所需数据，例如成本，平均成本，旅客人次等，以达到不同的研究目的。
         </p>
         <p>
          函数介绍：
         </p>
         <ul>
          <li>
           <code>
            readShapePoly()
           </code>
           ：读取图形文件用，建议直接将解压后的图形文件放在工程环境中。
          </li>
          <li>
           <code>
            fortify()
           </code>
           ：将地图数据转化为ggplot可以使用的格式。
          </li>
          <li>
           <code>
            gcIntermediate()
           </code>
           ：模拟圆弧，将两点间连线圆弧化。
          </li>
         </ul>
         <p>
          代码如下：
         </p>
         <pre># 读取都市地图文件 读取版图地图文件
urbanareasin &lt;- readShapePoly("ne_10m_urban_areas.shp")
worldmapsin &lt;- readShapePoly("ne_10m_admin_0_countries.shp")
# 以下为格式转化
worldmap &lt;- fortify(worldmapsin)
urbanareas &lt;- fortify(urbanareasin)
gpclibPermit()
# 开始抽取机场数据
airports &lt;- read.table("airports.dat", sep = ",", header = FALSE)
worldport &lt;- airports[airports$V5 != "", c("V3", "V5", 
    "V7", "V8", "V9")]
names(worldport) &lt;- c("city", "code", "lan", "lon", "att")
worldport$lan &lt;- as.numeric(as.character(worldport$lan))
worldport$lon &lt;- as.numeric(as.character(worldport$lon))
# 找出所有航线有标识的机场（这里的data3.redu2s是我个人的航线数据
# 读者可以用上文提到的航线数据routes.dat代替）
lineinworld &lt;- (data3.redu2s$AIRPORT_FROM_CODE %in% 
    worldport$code) &amp; (data3.redu2s$AIRPORT_TO_CODE %in% 
    worldport$code)
# 有243条航线无标识
table(lineinworld)
# colnames(data3.upro1)
worldline &lt;- data3.redu2s[lineinworld, c("AIRPORT_FROM_CODE", 
    "AIRPORT_TO_CODE")]
flights.ag &lt;- ddply(worldline, c("AIRPORT_FROM_CODE", 
    "AIRPORT_TO_CODE"), function(x) count(x$AIRPORT_TO_CODE))
# 计算三字码映射到机场
flights.ll &lt;- merge(flights.ag, worldport, by.x = "AIRPORT_TO_CODE", 
    by.y = "code", all.x = T)
flights.ll &lt;- flights.ll[order(flights.ll$AIRPORT_FROM_CODE, 
    flights.ll$AIRPORT_TO_CODE), ]
flights.lf &lt;- merge(flights.ag, worldport, by.x = "AIRPORT_FROM_CODE", 
    by.y = "code", all.x = T)
flights.lf &lt;- flights.lf[order(flights.lf$AIRPORT_FROM_CODE, 
    flights.lf$AIRPORT_TO_CODE), ]
# beijing.ll &lt;-
# c(worldport$lon[worldport$code=='PEK'], worldport$lan[worldport$code=='PEK'])
rts &lt;- gcIntermediate(flights.lf[, c("lon", "lan")], 
    flights.ll[, c("lon", "lan")], 100, breakAtDateLine = FALSE, 
    addStartEnd = TRUE, sp = TRUE)
# rts.ff &lt;-
# fortify.SpatialLinesDataFrame(rts)flights.lf[,c('lon', 'lan')]
rts &lt;- as(rts, "SpatialLinesDataFrame")
# 航线坐标数据
rts.ff &lt;- fortify(rts)
# 航线信息与航线坐标信息关联
flights.ll$id &lt;- as.character(c(1:nrow(flights.ll)))
table(gcircles$freq)
gcircles &lt;- merge(rts.ff, flights.ll, all.x = T, by = "id")</pre>
         <p>
          如代码中的注释所述，data3.redu2s这个变量可以从routes.dat读取得到，过程如下：
         </p>
         <pre>data3.redu2s &lt;- read.table("routes.dat", sep = ",", header = FALSE)
colnames(data3.redu2s)[c(3, 5)] &lt;- c("AIRPORT_FROM_<wbr></wbr>CODE",
                                     "AIRPORT_TO_CODE")</pre>
         <h2>
          四、地图旋转
         </h2>
         <p>
          这一步是对地图进行坐标变换，设置中国为世界中心，这里做了简单的坐标加减运算。代码如下：
         </p>
         <pre>center &lt;- 115
# 航线坐标计算中心距离
gcircles$long.recenter &lt;- ifelse(gcircles$long &lt; center - 
    180, gcircles$long + 360, gcircles$long)
# shift coordinates to recenter worldmap worldmap
# &lt;- map_data ('world') 地图坐标偏移
worldmap$long.recenter &lt;- ifelse(worldmap$long &lt; center - 
    180, worldmap$long + 360, worldmap$long)
urbanareas$long.recenter &lt;- ifelse(urbanareas$long &lt; 
    center - 180, urbanareas$long + 360, urbanareas$long</pre>
         <p>
          由于地图是图形数据，若是简单移动，地图会被切割，绘制时会出现图形变形等错误，故需要对地图数据进行再处理。该过程分为两步：
         </p>
         <ul>
          <li>
           处理1：图形切割后，切割图形重分组。
          </li>
          <li>
           处理2：重分组后，非闭合图形，闭合处理。
          </li>
         </ul>
         <h3>
          1. 切割图形重分组
         </h3>
         <p>
          在参考文献中提到的方法如下：
         </p>
         <pre>RegroupElements &lt;- function(df, longcol, idcol) {
    g &lt;- rep(1, length(df[, longcol]))
    if (diff(range(df[, longcol])) &gt; 300) {
        # check if longitude within group differs more than
        # 300 deg, ie if element was split
        # we use the mean to help us separate the extreme values
        d &lt;- df[, longcol] &gt; mean(range(df[, longcol]))
        # some marker for parts that stay in place
        # (we cheat here a little, as we do not take into account concave polygons)
        g[!d] &lt;- 1
        g[d] &lt;- 2  # parts that are moved
    }
    # attach to id to create unique group variable for the dataset
    g &lt;- paste(df[, idcol], g, sep = ".")
    df$group.regroup &lt;- g
    df
}
gcircles.rg &lt;- ddply(gcircles, .(id), RegroupElements, "long.recenter", "id")</pre>
         <p>
          以上方法，计算少量图形数据时（如gcircles）效果尚可。但一旦数据量级提高，其计算效率将极低。笔者电脑（10G内存）运行 urbanareas 数据，内存占用一度爆表，而且40多分钟未出结果。所以笔者重写了该算法，重写后占用内存可忽略，10秒内计算完成。
         </p>
         <p>
          改进算法如下：
         </p>
         <pre># 开始写原始算法替换函数 世界地图重分组
worldmap.mean &lt;- aggregate(x = worldmap[, c("long.recenter")], 
    by = list(worldmap$group), FUN = mean)
worldmap.min &lt;- aggregate(x = worldmap[, c("long.recenter")], 
    by = list(worldmap$group), FUN = min)
worldmap.max &lt;- aggregate(x = worldmap[, c("long.recenter")], 
    by = list(worldmap$group), FUN = max)
worldmap.md &lt;- cbind(worldmap.mean, worldmap.min[, 
    2], worldmap.max[, 2])
colnames(worldmap.md) &lt;- c("group", "mean", "min", "max")
worldmapt &lt;- join(x = worldmap, y = worldmap.md, by = c("group"))
worldmapt$group.regroup &lt;- 1
worldmapt[(worldmapt$max &gt; 180) &amp; (worldmapt$min &lt; 
    180) &amp; (worldmapt$long.recenter &gt; 180), c("group.regroup")] &lt;- 2
worldmapt$group.regroup &lt;- paste(worldmapt$group, worldmapt$group.regroup, 
    sep = ".")
worldmap.rg &lt;- worldmapt

# 都市地图重分组
urbanareas.mean &lt;- aggregate(x = urbanareas[, c("long.recenter")], 
    by = list(urbanareas$group), FUN = mean)
urbanareas.min &lt;- aggregate(x = urbanareas[, c("long.recenter")], 
    by = list(urbanareas$group), FUN = min)
urbanareas.max &lt;- aggregate(x = urbanareas[, c("long.recenter")], 
    by = list(urbanareas$group), FUN = max)
urbanareas.md &lt;- cbind(urbanareas.mean, urbanareas.min[, 
    2], urbanareas.max[, 2])
colnames(urbanareas.md) &lt;- c("group", "mean", "min", "max")
urbanareast &lt;- join(x = urbanareas, y = urbanareas.md, 
    by = c("group"))
urbanareast$group.regroup &lt;- 1
urbanareast[(urbanareast$max &gt; 180) &amp; (urbanareast$min &lt; 
    180) &amp; (urbanareast$long.recenter &gt; 180), c("group.regroup")] &lt;- 2
urbanareast$group.regroup &lt;- paste(urbanareast$group, 
    urbanareast$group.regroup, sep = ".")
urbanareas.rg &lt;- urbanareast</pre>
         <h3>
          2. 闭合曲线
         </h3>
         <p>
          闭合曲线原文也存在算法效率低缺陷，直接上重写的算法：
         </p>
         <pre># 闭合曲线
worldmap.rg &lt;- worldmap.rg[order(worldmap.rg$group.regroup, 
    worldmap.rg$order), ]
worldmap.begin &lt;- worldmap.rg[!duplicated(worldmap.rg$group.regroup), 
    ]
worldmap.end &lt;- worldmap.rg[c(!duplicated(worldmap.rg$group.regroup)[-1], 
    TRUE), ]
worldmap.flag &lt;- (worldmap.begin$long.recenter == worldmap.end$long.recenter) &amp; 
    (worldmap.begin$lat == worldmap.end$lat)
table(worldmap.flag)
worldmap.plus &lt;- worldmap.begin[!worldmap.flag, ]
worldmap.end[!worldmap.flag, ]
worldmap.plus$order &lt;- worldmap.end$order[!worldmap.flag] + 1
worldmap.cp &lt;- rbind(worldmap.rg, worldmap.plus)
worldmap.cp &lt;- worldmap.cp[order(worldmap.cp$group.regroup, 
    worldmap.cp$order), ]
urbanareas.rg &lt;- urbanareas.rg[order(urbanareas.rg$group.regroup, 
    urbanareas.rg$order), ]
urbanareas.begin &lt;- urbanareas.rg[!duplicated(urbanareas.rg$group.regroup), ]
urbanareas.end &lt;- urbanareas.rg[c(!duplicated(urbanareas.rg$group.regroup)[-1], 
    TRUE), ]
urbanareas.flag &lt;- (urbanareas.begin$long.recenter == 
    urbanareas.end$long.recenter) &amp; (urbanareas.begin$lat == 
    urbanareas.end$lat)
table(urbanareas.flag)
urbanareas.plus &lt;- urbanareas.begin[!urbanareas.flag, ]
urbanareas.end[!urbanareas.flag, ]
urbanareas.plus$order &lt;- urbanareas.end$order[!urbanareas.flag] + 1
urbanareas.cp &lt;- rbind(urbanareas.rg, urbanareas.plus)
urbanareas.cp &lt;- urbanareas.cp[order(urbanareas.cp$group.regroup, 
    urbanareas.cp$order), ]</pre>
         <h2>
          五、绘制图像
         </h2>
         <p>
          数据齐全了，该绘制图像了。本文绘制图像使用了ggplot函数，由于ggplot2的参考书籍较多，因此相关函数就不一一介绍。地图的设计是可通过调节放大系数以输出不同品质的图像，主要分两步：
         </p>
         <h3>
          1. 绘制背景
         </h3>
         <p>
          背景是点线地图，而且精度较高，夜景图边界线意义不大，因此处理起来较简单。代码如下：
         </p>
         <pre>wrld &lt;- geom_polygon(aes(long.recenter, lat, group = group.regroup), 
    size = 0.1, colour = "#090D2A", fill = "#090D2A", 
    alpha = 1, data = worldmap.cp)
urb &lt;- geom_polygon(aes(long.recenter, lat, group = group.regroup), 
    size = 0.3, color = "#FDF5E6", fill = "#FDF5E6", 
    alpha = 1, data = urbanareas.cp)</pre>
         <h3>
          2. 绘制航线
         </h3>
         <p>
          航线是由线组成的，放大时线的宽度、光晕宽度变化比例与图形变化比例不一致，需要分开调节。根据图形知识，该变化应是函数关系。这里给出一种较美观的函数关系，有兴趣的同学可以继续优化该函数。另外本文与原地图的一个不同之处是增加了光晕效果，图片十分绚丽。其原理是使用高透明度的辅助线。线的光晕亮度和航线频率相关，相关的代码如下：
         </p>
         <pre># 放大系数
bigmap &lt;- 1
airline &lt;- geom_line(aes(long.recenter, lat, group = group.regroup, 
    alpha = max(freq)^0.6 * freq^0.4, color = 0.9 * 
        max(freq)^0.6 * freq^0.4), size = 0.2 * bigmap, 
    data = gcircles.rg)
airlinep &lt;- geom_line(aes(long.recenter, lat, group = group.regroup, 
    alpha = 0.04 * max(freq)^0.6 * freq^0.4), color = "#FFFFFF", 
    size = 2 * bigmap, data = gcircles.rg)
# table(gcircles.rg$freq)
airlinepp &lt;- geom_line(aes(long.recenter, lat, group = group.regroup, 
    alpha = 0.02 * max(freq)^0.6 * freq^0.4), color = "#ECFFFF", 
    size = 4 * bigmap, data = gcircles.rg)
airlineppp &lt;- geom_line(aes(long.recenter, lat, group = group.regroup, 
    alpha = 0.01 * max(freq)^0.6 * freq^0.4), color = "#ECFFFF", 
    size = 8 * bigmap, data = gcircles.rg)
airlinepppp &lt;- geom_line(aes(long.recenter, lat,
    group = group.regroup, 
    alpha = 0.005 * max(freq)^0.6 * freq^0.4), color = "#BBFFFF", 
    size = 16 * bigmap, data = gcircles.rg)
gcircles.rg[gcircles.rg$group.regroup == 1.1, ]

# plot画图到文件plot2.png
png(6000 * (bigmap^0.8), 2000 * (bigmap^0.8), file = "plot2.png", 
    bg = "white")
ggplot() + wrld + urb + airline +
    scale_colour_gradient(low = "#D9FFFF", high = "#ECFFFF") +
    scale_alpha(range = c(0, 1)) + 
    airlineppp +
    # scale_alpha_discrete(range = c(0.001, 0.005)) +
    airlinepp +
    # scale_alpha(range = c(0.005, 0.015))+
    airlinep +
    # scale_alpha(range = c(0.015, 0.08)) +
# geom_polygon(aes(long,lat,group = group), size = 0.2,
#     fill = '#f9f9f9', colour = 'grey65', data = worldmap) +
# geom_line(aes(long.recenter,lat,group = group.regroup, color = freq,
#     alpha = freq), size = 0.4, data = gcircles.rg) +
    theme(
        panel.background = element_rect(fill = "#00001C",
            color = "#00001C"),
        panel.grid = element_blank(), 
        axis.ticks = element_blank(), 
        axis.title = element_blank(),
        axis.text = element_blank(),
        legend.position = "none")
    ) + ylim(-65, 75) + coord_equal()
dev.off()</pre>
         <p>
          完整尺寸的超清航线夜景图可以在
          <a href="http://cos.name/wp-content/uploads/2014/09/flight-night-scene-HD.png" target="_blank">
           这里下载
          </a>
          得到（7.9M）。
         </p>
         <div class="wumii-hook">
          <br/>
          <br/>
         </div>
        </div>
        <!-- .entry-content -->
        <footer class="entry-meta">
         <div class="author-info">
          <div class="author-avatar">
           <img src="http://sdn.geekzu.org/avatar/2fe058e9e383c85afa949b36e869432f?s=74&amp;d=monsterid&amp;r=g"/>
          </div>
          <!-- .author-avatar -->
          <div class="author-description">
           <h2 class="author-title">
            关于COS编辑部
           </h2>
           <p class="author-bio">
            本账户为COS编辑部公共账户，目前由朱雪宁任主编，王小宁任副主编，编辑有：冯璟烁、吴佳萍、张心雨、施涛、霍志骥、何通、冷静、尤晓斌、肖楠、邱怡轩、高涛、谢益辉等人，主要负责主站文章的规范化编辑以及相关论文、书籍、手册的整理、编纂、出版等工作。
            <a class="author-link" href="http://cos.name/author/editor/" rel="author">
             查看所有由COS编辑部发表的文章
             <span class="meta-nav">
              →
             </span>
            </a>
           </p>
          </div>
          <!-- .author-description -->
         </div>
         <!-- .author-info -->
        </footer>
        <!-- .entry-meta -->
       </article>
       <!-- #post -->
       <nav class="navigation post-navigation" role="navigation">
        <h1 class="screen-reader-text">
         文章导航
        </h1>
        <div class="nav-links">
         <a href="http://cos.name/2014/09/let-us-own-data-science/" rel="prev">
          <span class="meta-nav">
           ←
          </span>
          郁彬：让我们拥抱数据科学（Let us own data science）
         </a>
         <a href="http://cos.name/2014/10/7th-r-conference-guangzhou/" rel="next">
          第七届中国R语言会议（广州会场）通知
          <span class="meta-nav">
           →
          </span>
         </a>
        </div>
        <!-- .nav-links -->
       </nav>
       <!-- .navigation -->
       <div class="comments-area" id="comments">
        <h2 class="comments-title">
         《
         <span>
          R绘制中国航线分布夜景图
         </span>
         》有17个想法
        </h2>
        <ol class="comment-list">
         <li class="comment even thread-even depth-1" id="comment-6235">
          <article class="comment-body" id="div-comment-6235">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              云梦居客
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6235">
              <time datetime="2014-09-27T17:41:03+00:00">
               2014/09/27 17:41
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             好东西，学习了
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给云梦居客" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6235#respond" onclick='return addComment.moveForm( "div-comment-6235", "6235", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
         </li>
         <!-- #comment-## -->
         <li class="comment odd alt thread-odd thread-alt depth-1" id="comment-6239">
          <article class="comment-body" id="div-comment-6239">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              <a class="url" href="http://weibo.com/2775232100" rel="external nofollow">
               叶飘潇雨
              </a>
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6239">
              <time datetime="2014-09-29T21:55:46+00:00">
               2014/09/29 21:55
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             好赞，学习一下了啊
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给叶飘潇雨" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6239#respond" onclick='return addComment.moveForm( "div-comment-6239", "6239", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
         </li>
         <!-- #comment-## -->
         <li class="comment even thread-even depth-1" id="comment-6251">
          <article class="comment-body" id="div-comment-6251">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/163fcd09b5bced011c0c0256b5d07449?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              Jonee
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6251">
              <time datetime="2014-10-03T22:09:20+00:00">
               2014/10/03 22:09
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             学习了！内容详实，有时间自己照着做一遍试试。
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给Jonee" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6251#respond" onclick='return addComment.moveForm( "div-comment-6251", "6251", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
         </li>
         <!-- #comment-## -->
         <li class="comment odd alt thread-odd thread-alt depth-1 parent" id="comment-6253">
          <article class="comment-body" id="div-comment-6253">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/b7cd2769fda00e5d0bb3b2feea6cfd5b?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              小龙
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6253">
              <time datetime="2014-10-04T17:07:01+00:00">
               2014/10/04 17:07
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             flights.ag &lt;- ddply(worldline, c("AIRPORT_FROM_CODE",  "AIRPORT_TO_CODE"),
             <br/>
             function(x) count(x$AIRPORT_TO_CODE))
             <br/>
             这个是想求每个机场出发的航班数吗？
             <br/>
             如果是的话有两点：
             <br/>
             （1）新的dplyr无法运作上述函数；
             <br/>
             （2）可以通过data.table快速求出。
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给小龙" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6253#respond" onclick='return addComment.moveForm( "div-comment-6253", "6253", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
          <ol class="children">
           <li class="comment even depth-2" id="comment-6316">
            <article class="comment-body" id="div-comment-6316">
             <footer class="comment-meta">
              <div class="comment-author vcard">
               <img src="http://sdn.geekzu.org/avatar/?s=74&amp;d=monsterid&amp;r=g"/>
               <b class="fn">
                <a class="url" href="http://weibo.com/2694610754" rel="external nofollow">
                 梦中渴望会飞的鱼_O21
                </a>
               </b>
               <span class="says">
                说道：
               </span>
              </div>
              <!-- .comment-author -->
              <div class="comment-metadata">
               <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6316">
                <time datetime="2014-10-27T13:39:01+00:00">
                 2014/10/27 13:39
                </time>
               </a>
              </div>
              <!-- .comment-metadata -->
             </footer>
             <!-- .comment-meta -->
             <div class="comment-content">
              <p>
               您好，请问这个问题现在您有解答了吗？我在运行这一行的时候内存爆表，好久都出不来结果。。不知道能不能用其他代码替换呢？
              </p>
             </div>
             <!-- .comment-content -->
             <div class="reply">
              <a aria-label="回复给梦中渴望会飞的鱼_O21" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6316#respond" onclick='return addComment.moveForm( "div-comment-6316", "6316", "respond", "10259" )' rel="nofollow">
               回复
              </a>
             </div>
            </article>
            <!-- .comment-body -->
           </li>
           <!-- #comment-## -->
          </ol>
          <!-- .children -->
         </li>
         <!-- #comment-## -->
         <li class="comment odd alt thread-even depth-1 parent" id="comment-6254">
          <article class="comment-body" id="div-comment-6254">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/b7cd2769fda00e5d0bb3b2feea6cfd5b?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              X
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6254">
              <time datetime="2014-10-04T17:25:34+00:00">
               2014/10/04 17:25
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             应该是两个机场间的航线数。可以用下式求出：
             <br/>
             worldline = as.data.table(worldline) # &gt; unique(worldline)
             <br/>
             flights.ag &lt;- as.data.frame(worldline[, .N, keyby = c("AIRPORT_FROM_CODE", "AIRPORT_TO_CODE")])
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给X" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6254#respond" onclick='return addComment.moveForm( "div-comment-6254", "6254", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
          <ol class="children">
           <li class="comment even depth-2 parent" id="comment-6317">
            <article class="comment-body" id="div-comment-6317">
             <footer class="comment-meta">
              <div class="comment-author vcard">
               <img src="http://sdn.geekzu.org/avatar/?s=74&amp;d=monsterid&amp;r=g"/>
               <b class="fn">
                <a class="url" href="http://weibo.com/2694610754" rel="external nofollow">
                 梦中渴望会飞的鱼_O21
                </a>
               </b>
               <span class="says">
                说道：
               </span>
              </div>
              <!-- .comment-author -->
              <div class="comment-metadata">
               <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6317">
                <time datetime="2014-10-27T13:49:39+00:00">
                 2014/10/27 13:49
                </time>
               </a>
              </div>
              <!-- .comment-metadata -->
             </footer>
             <!-- .comment-meta -->
             <div class="comment-content">
              <p>
               提示as.data.table不存在啊
              </p>
             </div>
             <!-- .comment-content -->
             <div class="reply">
              <a aria-label="回复给梦中渴望会飞的鱼_O21" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6317#respond" onclick='return addComment.moveForm( "div-comment-6317", "6317", "respond", "10259" )' rel="nofollow">
               回复
              </a>
             </div>
            </article>
            <!-- .comment-body -->
            <ol class="children">
             <li class="comment odd alt depth-3 parent" id="comment-6318">
              <article class="comment-body" id="div-comment-6318">
               <footer class="comment-meta">
                <div class="comment-author vcard">
                 <img src="http://sdn.geekzu.org/avatar/b7cd2769fda00e5d0bb3b2feea6cfd5b?s=74&amp;d=monsterid&amp;r=g"/>
                 <b class="fn">
                  X
                 </b>
                 <span class="says">
                  说道：
                 </span>
                </div>
                <!-- .comment-author -->
                <div class="comment-metadata">
                 <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6318">
                  <time datetime="2014-10-27T15:16:12+00:00">
                   2014/10/27 15:16
                  </time>
                 </a>
                </div>
                <!-- .comment-metadata -->
               </footer>
               <!-- .comment-meta -->
               <div class="comment-content">
                <p>
                 先装data.table包，不过他的函数求航班数还是太耗时，我后来没有基于这个修改
                </p>
               </div>
               <!-- .comment-content -->
              </article>
              <!-- .comment-body -->
             </li>
             <!-- #comment-## -->
             <li class="comment even depth-3" id="comment-6320">
              <article class="comment-body" id="div-comment-6320">
               <footer class="comment-meta">
                <div class="comment-author vcard">
                 <img src="http://sdn.geekzu.org/avatar/?s=74&amp;d=monsterid&amp;r=g"/>
                 <b class="fn">
                  <a class="url" href="http://weibo.com/2694610754" rel="external nofollow">
                   梦中渴望会飞的鱼_O21
                  </a>
                 </b>
                 <span class="says">
                  说道：
                 </span>
                </div>
                <!-- .comment-author -->
                <div class="comment-metadata">
                 <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6320">
                  <time datetime="2014-10-27T17:38:54+00:00">
                   2014/10/27 17:38
                  </time>
                 </a>
                </div>
                <!-- .comment-metadata -->
               </footer>
               <!-- .comment-meta -->
               <div class="comment-content">
                <p>
                 是啊。按照他的方法求航班数，电脑内存直接爆表，半个小时都出不来结果。不知道你后来是怎么改进的呢？方便交流一下吗？
                </p>
               </div>
               <!-- .comment-content -->
              </article>
              <!-- .comment-body -->
             </li>
             <!-- #comment-## -->
            </ol>
            <!-- .children -->
           </li>
           <!-- #comment-## -->
          </ol>
          <!-- .children -->
         </li>
         <!-- #comment-## -->
         <li class="comment odd alt thread-odd thread-alt depth-1" id="comment-6256">
          <article class="comment-body" id="div-comment-6256">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/b7cd2769fda00e5d0bb3b2feea6cfd5b?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              X
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6256">
              <time datetime="2014-10-04T21:37:21+00:00">
               2014/10/04 21:37
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             航线坐标转换要多长时间啊，电脑太慢了
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给X" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6256#respond" onclick='return addComment.moveForm( "div-comment-6256", "6256", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
         </li>
         <!-- #comment-## -->
         <li class="comment even thread-even depth-1" id="comment-6264">
          <article class="comment-body" id="div-comment-6264">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              <a class="url" href="http://weibo.com/hustpast" rel="external nofollow">
               hhuster
              </a>
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6264">
              <time datetime="2014-10-07T17:43:37+00:00">
               2014/10/07 17:43
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             操作性不错
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给hhuster" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6264#respond" onclick='return addComment.moveForm( "div-comment-6264", "6264", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
         </li>
         <!-- #comment-## -->
         <li class="comment odd alt thread-odd thread-alt depth-1" id="comment-6306">
          <article class="comment-body" id="div-comment-6306">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/f7c557fd3ae3c69dd67b973367b63797?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              adpose
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6306">
              <time datetime="2014-10-23T09:59:01+00:00">
               2014/10/23 09:59
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             Error: cannot allocate vector of size 484.9 Mb
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给adpose" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6306#respond" onclick='return addComment.moveForm( "div-comment-6306", "6306", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
         </li>
         <!-- #comment-## -->
         <li class="comment even thread-even depth-1" id="comment-6310">
          <article class="comment-body" id="div-comment-6310">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              <a class="url" href="http://weibo.com/1875547461" rel="external nofollow">
               雪域雨城
              </a>
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6310">
              <time datetime="2014-10-24T19:48:38+00:00">
               2014/10/24 19:48
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             您好，ubuntu 12.04下没有这
             <br/>
             geos-devel-3.2.2
             <br/>
             geos-3.2.2
             <br/>
             两个东西，有什么替代？
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给雪域雨城" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6310#respond" onclick='return addComment.moveForm( "div-comment-6310", "6310", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
         </li>
         <!-- #comment-## -->
         <li class="comment odd alt thread-odd thread-alt depth-1" id="comment-6356">
          <article class="comment-body" id="div-comment-6356">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              <a class="url" href="http://t.qq.com/xp1273611645" rel="external nofollow">
               徐鹏
              </a>
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-6356">
              <time datetime="2014-11-11T10:50:17+00:00">
               2014/11/11 10:50
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             刚刚学习R，ggmap包，怎么加载进去
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给徐鹏" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=6356#respond" onclick='return addComment.moveForm( "div-comment-6356", "6356", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
         </li>
         <!-- #comment-## -->
         <li class="pingback even thread-even depth-1" id="comment-6464">
          <div class="comment-body">
           Pingback：
           <a class="url" href="http://www.cellyse.com/how_to_use_gggplot2/" rel="external nofollow">
            ggplot2入门与进阶 | 塞迩斯
           </a>
          </div>
         </li>
         <!-- #comment-## -->
         <li class="comment odd alt thread-odd thread-alt depth-1 parent" id="comment-7044">
          <article class="comment-body" id="div-comment-7044">
           <footer class="comment-meta">
            <div class="comment-author vcard">
             <img src="http://sdn.geekzu.org/avatar/fa378c658ff45983bbb607f1c03f8d37?s=74&amp;d=monsterid&amp;r=g"/>
             <b class="fn">
              <a class="url" href="http://暨南大学" rel="external nofollow">
               梁政华
              </a>
             </b>
             <span class="says">
              说道：
             </span>
            </div>
            <!-- .comment-author -->
            <div class="comment-metadata">
             <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-7044">
              <time datetime="2016-01-25T10:36:22+00:00">
               2016/01/25 10:36
              </time>
             </a>
            </div>
            <!-- .comment-metadata -->
           </footer>
           <!-- .comment-meta -->
           <div class="comment-content">
            <p>
             你好！绘图那里需要的数据框是gcircle.rg，而文中改进的代码是分开求worldmap.rg，和urbanareas.rg，请问怎么转换成后文的gcircle.rg?
            </p>
           </div>
           <!-- .comment-content -->
           <div class="reply">
            <a aria-label="回复给梁政华" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=7044#respond" onclick='return addComment.moveForm( "div-comment-7044", "7044", "respond", "10259" )' rel="nofollow">
             回复
            </a>
           </div>
          </article>
          <!-- .comment-body -->
          <ol class="children">
           <li class="comment even depth-2" id="comment-7182">
            <article class="comment-body" id="div-comment-7182">
             <footer class="comment-meta">
              <div class="comment-author vcard">
               <img src="http://sdn.geekzu.org/avatar/5f34dc5ba3b6d67bb81c89fde4f21ce3?s=74&amp;d=monsterid&amp;r=g"/>
               <b class="fn">
                playaholic
               </b>
               <span class="says">
                说道：
               </span>
              </div>
              <!-- .comment-author -->
              <div class="comment-metadata">
               <a href="http://cos.name/2014/09/visualizing-flights-data/#comment-7182">
                <time datetime="2016-04-21T15:19:58+00:00">
                 2016/04/21 15:19
                </time>
               </a>
              </div>
              <!-- .comment-metadata -->
             </footer>
             <!-- .comment-meta -->
             <div class="comment-content">
              <p>
               同问
              </p>
             </div>
             <!-- .comment-content -->
             <div class="reply">
              <a aria-label="回复给playaholic" class="comment-reply-link" href="http://cos.name/2014/09/visualizing-flights-data/?replytocom=7182#respond" onclick='return addComment.moveForm( "div-comment-7182", "7182", "respond", "10259" )' rel="nofollow">
               回复
              </a>
             </div>
            </article>
            <!-- .comment-body -->
           </li>
           <!-- #comment-## -->
          </ol>
          <!-- .children -->
         </li>
         <!-- #comment-## -->
        </ol>
        <!-- .comment-list -->
        <div class="comment-respond" id="respond">
         <h3 class="comment-reply-title" id="reply-title">
          发表评论
          <small>
           <a href="http://cos.name/2014/09/visualizing-flights-data/#respond" id="cancel-comment-reply-link" rel="nofollow" style="display:none;">
            取消回复
           </a>
          </small>
         </h3>
         <form action="http://cos.name/wp-comments-post.php" class="comment-form" id="commentform" method="post" novalidate="">
          <p class="comment-notes">
           <span id="email-notes">
            电子邮件地址不会被公开。
           </span>
           必填项已用
           <span class="required">
            *
           </span>
           标注
          </p>
          <p class="comment-form-comment">
           <label for="comment">
            评论
           </label>
           <textarea aria-required="true" cols="45" id="comment" maxlength="65525" name="comment" required="required" rows="8">
           </textarea>
          </p>
          <p class="comment-form-author">
           <label for="author">
            姓名
            <span class="required">
             *
            </span>
           </label>
          </p>
          <p class="comment-form-email">
           <label for="email">
            电子邮件
            <span class="required">
             *
            </span>
           </label>
          </p>
          <p class="comment-form-url">
           <label for="url">
            站点
           </label>
          </p>
          <p class="form-submit">
          </p>
          <p style="display: none;">
          </p>
          <p style="display: none;">
          </p>
         </form>
        </div>
        <!-- #respond -->
       </div>
       <!-- #comments -->
      </div>
      <!-- #content -->
     </div>
     <!-- #primary -->
     <div class="sidebar-container" id="tertiary" role="complementary">
      <div class="sidebar-inner">
       <div class="widget-area">
        <aside class="widget widget_text" id="text-3">
         <h3 class="widget-title">
          关注统计之都
         </h3>
         <div class="textwidget">
          <ul>
           <li>
            新浪微博
            <a href="http://weibo.com/cosname">
             @统计之都
            </a>
           </li>
           <li>
            人人网
            <a href="http://renren.com/cosname">
             @统计之都
            </a>
           </li>
           <li>
            Twitter
            <a href="http://twitter.com/cos_name">
             @cos_name
            </a>
           </li>
          </ul>
         </div>
        </aside>
        <aside class="widget widget_text" id="text-6">
         <h3 class="widget-title">
          微信公众平台
         </h3>
         <div class="textwidget">
          <img src="http://cos.name/wp-content/uploads/2013/04/qrcode-8cm.jpg"/>
          <p style="font-size:12px;margin-left:15px">
           微信号 CapStat
          </p>
          <p>
           我们将第一时间向您推送主站和论坛的精彩内容，以及统计之都的线下活动、竞赛、培训和会议信息。
          </p>
         </div>
        </aside>
        <aside class="widget widget_text" id="text-8">
         <h3 class="widget-title">
          站内导航
         </h3>
         <div class="textwidget">
          <ul>
           <li class="page_item">
            <a href="http://cos.name/cn/">
             中文论坛
            </a>
           </li>
           <li class="page_item">
            <a href="http://cos.name/videos/">
             视频
            </a>
           </li>
           <li class="page_item">
            <a href="http://cos.name/salon/">
             统计沙龙
            </a>
           </li>
           <li class="page_item">
            <a href="http://cos.name/books/">
             图书出版
            </a>
           </li>
           <li class="page_item">
            <a href="http://cos.name/training/">
             教育培训
            </a>
           </li>
           <li class="page_item">
            <a href="http://cos.name/about/">
             关于我们
            </a>
           </li>
           <li class="page_item">
            <a href="http://cos.name/donate/">
             捐赠
            </a>
           </li>
           <li class="page_item">
            <a href="http://cos.name/chinar/">
             R语言会议
            </a>
           </li>
          </ul>
         </div>
        </aside>
        <aside class="widget widget_links" id="linkcat-2">
         <h3 class="widget-title">
          友情链接
         </h3>
         <ul class="xoxo blogroll">
          <li>
           <a href="http://stat.ruc.edu.cn" target="_blank" title="中国人民大学统计学院网站">
            中国人民大学统计学院
           </a>
          </li>
          <li>
           <a href="http://rucdmc.net">
            中国人民大学数据挖掘中心
           </a>
          </li>
          <li>
           <a href="http://birc.gsm.pku.edu.cn/" target="_blank">
            北京大学商务智能研究中心
           </a>
          </li>
          <li>
           <a href="http://sam.cufe.edu.cn/" target="_blank" title="中央财经大学统计与数学学院网站">
            中央财经大学统计与数学学院
           </a>
          </li>
          <li>
           <a href="http://tjx.cueb.edu.cn/" target="_blank" title="首都经济贸易大学统计学院网站">
            首经贸统计学院
           </a>
          </li>
          <li>
           <a href="http://www.shookr.com/">
            数客网大数据社区
           </a>
          </li>
          <li>
           <a href="http://www.xueqing.tv/" target="_blank" title="数据科学在线学习平台">
            雪晴数据网
           </a>
          </li>
          <li>
           <a href="http://iera.name/" target="_blank" title="IERA是一个旨在普及、传播和增进工业工程知识的非营利性网站">
            IERA（直通IE）
           </a>
          </li>
         </ul>
        </aside>
        <aside class="widget widget_categories" id="categories-2">
         <h3 class="widget-title">
          全部分类
         </h3>
         <label class="screen-reader-text" for="cat">
          全部分类
         </label>
         <select class="postform" id="cat" name="cat">
          <option value="-1">
           选择分类目录
          </option>
          <option class="level-0" value="925">
           cos访谈  (4)
          </option>
          <option class="level-0" value="659">
           图书出版  (5)
          </option>
          <option class="level-0" value="379">
           数学方法  (14)
          </option>
          <option class="level-1" value="381">
           分析与代数  (1)
          </option>
          <option class="level-1" value="380">
           概率论  (9)
          </option>
          <option class="level-1" value="382">
           随机过程  (5)
          </option>
          <option class="level-0" value="210">
           数据分析  (81)
          </option>
          <option class="level-1" value="203">
           多元统计  (3)
          </option>
          <option class="level-1" value="42">
           数据挖掘与机器学习  (42)
          </option>
          <option class="level-1" value="36">
           生物与医学统计  (17)
          </option>
          <option class="level-1" value="35">
           计量经济学  (4)
          </option>
          <option class="level-1" value="296">
           金融统计  (3)
          </option>
          <option class="level-1" value="303">
           风险精算  (7)
          </option>
          <option class="level-0" value="177">
           模型专题  (15)
          </option>
          <option class="level-1" value="38">
           回归分析  (10)
          </option>
          <option class="level-1" value="41">
           时间序列  (2)
          </option>
          <option class="level-0" value="784">
           每周精选  (24)
          </option>
          <option class="level-1" value="183">
           可视化  (9)
          </option>
          <option class="level-0" value="967">
           沙龙纪要  (3)
          </option>
          <option class="level-0" value="18">
           经典理论  (46)
          </option>
          <option class="level-1" value="37">
           抽样调查  (3)
          </option>
          <option class="level-1" value="4">
           统计推断  (26)
          </option>
          <option class="level-1" value="236">
           试验设计  (7)
          </option>
          <option class="level-1" value="39">
           非参数统计  (3)
          </option>
          <option class="level-0" value="1">
           统计之都  (279)
          </option>
          <option class="level-1" value="884">
           中国R会议  (2)
          </option>
          <option class="level-1" value="885">
           中国R语言会议  (5)
          </option>
          <option class="level-1" value="446">
           出国留学  (3)
          </option>
          <option class="level-1" value="179">
           推荐文章  (90)
          </option>
          <option class="level-1" value="3">
           新闻通知  (75)
          </option>
          <option class="level-1" value="263">
           统计刊物  (10)
          </option>
          <option class="level-1" value="174">
           网站导读  (40)
          </option>
          <option class="level-1" value="204">
           职业事业  (51)
          </option>
          <option class="level-1" value="213">
           高校课堂  (9)
          </option>
          <option class="level-0" value="178">
           统计计算  (28)
          </option>
          <option class="level-1" value="40">
           优化与模拟  (15)
          </option>
          <option class="level-1" value="43">
           贝叶斯方法  (6)
          </option>
          <option class="level-0" value="378">
           软件应用  (116)
          </option>
          <option class="level-1" value="44">
           统计图形  (36)
          </option>
          <option class="level-1" value="110">
           统计软件  (83)
          </option>
         </select>
        </aside>
        <aside class="widget widget_recent_comments" id="recent-comments-2">
         <h3 class="widget-title">
          最新评论
         </h3>
         <ul id="recentcomments">
          <li class="recentcomments">
           <span class="comment-author-link">
            fineboom
           </span>
           发表在《
           <a href="http://cos.name/2016/06/use-shiny-fleetly-set-up-visual-prototype-system/#comment-7317">
            利用shiny包快速搭建可视化原型系统
           </a>
           》
          </li>
          <li class="recentcomments">
           <span class="comment-author-link">
            胡家新
           </span>
           发表在《
           <a href="http://cos.name/2016/06/r%e8%af%ad%e5%8d%83%e5%af%bb%e7%ac%ac%e4%b8%89%e6%9c%9f%ef%bc%9a%e5%bc%a0%e6%97%a0%e5%bf%8c%e7%a9%b6%e7%ab%9f%e7%88%b1%e8%b0%81%ef%bc%9f/#comment-7316">
            R语千寻第三期：张无忌究竟爱谁？
           </a>
           》
          </li>
          <li class="recentcomments">
           <span class="comment-author-link">
            <a class="url" href="http://www.zijiacha.com/category.php?id=6" rel="external nofollow">
             南糯山普洱茶
            </a>
           </span>
           发表在《
           <a href="http://cos.name/2016/06/r%e8%af%ad%e5%8d%83%e5%af%bb%e7%ac%ac%e4%b8%89%e6%9c%9f%ef%bc%9a%e5%bc%a0%e6%97%a0%e5%bf%8c%e7%a9%b6%e7%ab%9f%e7%88%b1%e8%b0%81%ef%bc%9f/#comment-7315">
            R语千寻第三期：张无忌究竟爱谁？
           </a>
           》
          </li>
          <li class="recentcomments">
           <span class="comment-author-link">
            J
           </span>
           发表在《
           <a href="http://cos.name/2016/05/value-of-the-reputation-from-the-data/#comment-7314">
            数据告诉你：高信誉的卖家应该收高价，还是收低价？
           </a>
           》
          </li>
          <li class="recentcomments">
           <span class="comment-author-link">
            <a class="url" href="http://gg" rel="external nofollow">
             Hilda
            </a>
           </span>
           发表在《
           <a href="http://cos.name/2013/01/drawing-map-in-r-era/#comment-7311">
            R时代，你要怎样画地图？
           </a>
           》
          </li>
         </ul>
        </aside>
        <aside class="widget widget_rss" id="rss-282869971">
         <h3 class="widget-title">
          <a class="rsswidget" href="http://cos.name/cn/topics/feed/">
           <img src="http://cos.name/wp-includes/images/rss.png"/>
          </a>
          <a class="rsswidget" href="http://cos.name/cn/topics/feed/">
           中文论坛新帖
          </a>
         </h3>
         <ul>
          <li>
           <a class="rsswidget" href="http://cos.name/cn/topic/417372/">
            处理时间数据和产生时间序列的问题
           </a>
          </li>
          <li>
           <a class="rsswidget" href="http://cos.name/cn/topic/6790/">
            《统计陷阱》下载 （How to lie with statistics）
           </a>
          </li>
          <li>
           <a class="rsswidget" href="http://cos.name/cn/topic/818/">
            统计学的世界（第五版）
           </a>
          </li>
          <li>
           <a class="rsswidget" href="http://cos.name/cn/topic/16574/">
            class(x) 返回值值是AsIs,AsIs代表什么，有什么用处？
           </a>
          </li>
          <li>
           <a class="rsswidget" href="http://cos.name/cn/topic/417366/">
            如何用R绘制一个分类算法的决策规则
           </a>
          </li>
         </ul>
        </aside>
        <aside class="widget widget_text" id="text-2">
         <h3 class="widget-title">
          登录/RSS
         </h3>
         <div class="textwidget">
          <ul>
           <li>
            <a href="http://cos.name/wp-admin/">
             登录
            </a>
           </li>
           <li>
            <a href="http://cos.name/feed/" title="使用 RSS 2.0 同步站点内容">
             文章
             <abbr title="Really Simple Syndication">
              RSS
             </abbr>
            </a>
           </li>
           <li>
            <a href="http://cos.name/comments/feed/" title="RSS 上的最近评论">
             评论
             <abbr title="Really Simple Syndication">
              RSS
             </abbr>
            </a>
           </li>
          </ul>
         </div>
        </aside>
       </div>
       <!-- .widget-area -->
      </div>
      <!-- .sidebar-inner -->
     </div>
     <!-- #tertiary -->
    </div>
    <!-- #main -->
    <footer class="site-footer" id="colophon" role="contentinfo">
     <div class="site-info">
      版权所有 © 2014 统计之都 | 由
      <a href="http://wordpress.org/">
       WordPress
      </a>
      构建 | 主题修改自
      <a href="http://wordpress.org/themes/twentythirteen">
       Twenty Thirteen
      </a>
     </div>
     <!-- .site-info -->
    </footer>
    <!-- #colophon -->
   </div>
   <!-- #page -->
   <p style="margin:0;padding:0;height:1px;overflow:hidden;">
    <a href="http://www.wumii.com/widget/relatedItems" style="border:0;">
     <img src="http://static.wumii.cn/images/pixel.png"/>
    </a>
   </p>
  </div>
 </body>
</html>